<template>
  <div class="card">
    <div class="body">
      <img src="@/assets/images/file-manager/doc.png" />
      <div class="text">
        <div class="title">{{ versionDetail.name }}</div>
        <div class="detail"
          >{{ versionDetail.updateBy }}于{{ versionDetail.updateDate }}上传{{
            versionDetail.name
          }}</div
        >
      </div>
    </div>
    <div class="foot">
      <a-tag size="small" color="arcoblue"
        >{{ currentFile?.version === versionDetail.version ? '当前 ' : '' }}v{{
          versionDetail.version
        }}</a-tag
      >
      <div class="buttons">
        <a-tooltip
          content="版本回退"
          position="br"
          @click="rollback(versionDetail.version || '')"
        >
          <icon-share-internal :size="16" class="svg-button" />
        </a-tooltip>
        <a-tooltip
          content="下载"
          position="br"
          @click="versionDownload(versionDetail)"
        >
          <icon-download :size="16" class="svg-button" />
        </a-tooltip>
        <a-tooltip
          content="复制"
          position="br"
          @click="versionCopy(versionDetail)"
        >
          <icon-copy :size="16" class="svg-button" />
        </a-tooltip>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { FileVersion } from '@/views/file-manage/api';
  import { PropType } from 'vue';
  import { storeToRefs } from 'pinia';
  import useFileManageStore from '@/store/modules/file-manage/index';
  import {
    versionCopy,
    rollback,
    versionDownload,
  } from '../hooks/dropdow-events';

  const store = useFileManageStore();
  const { currentFile } = storeToRefs(store);

  defineProps({
    versionDetail: {
      type: Object as PropType<FileVersion>,
      required: true,
    },
  });
</script>

<style lang="less" scoped>
  .card {
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 8px;
  }
  .foot {
    display: flex;
    justify-content: space-between;
    margin: 4px 0 0 4px;
  }
  .buttons {
    display: flex;
    align-items: flex-end;
  }
  svg + svg {
    margin-left: 10px;
  }
  .body {
    display: flex;
  }
  .text {
    margin-left: 12px;
    flex: 1;
  }
  .title {
    font-size: 14px;
    color: var(--color-text-1);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 236px;
  }
  .detail {
    font-size: 12px;
    color: var(--color-text-2);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 236px;
  }
  .body > img {
    width: 40px;
    height: 40px;
  }
  .svg-button {
    cursor: pointer;
  }
</style>
